<?php
$isadmin=1;
error_reporting(2);
if($_GET['sid']) session_id($_GET['sid']);
include '../comm/config.php';
include 'check.php';
include("upload.class.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="../js/jquery.js"></script>
<?php
$CONF['jpeg_enable']   = '1';
$CONF['gif_enable']   = '1';
$CONF['png_enable']   = '1';
function extend_2($file_name)   
{   
$extend = pathinfo($file_name);   
$extend = strtolower($extend["extension"]);   
return $extend;   
} 
$picname=array('gif','jpg','jpeg');
$uploadtext = $_GET['uploadtext'];
if (is_uploaded_file($_FILES[$uploadtext]['tmp_name'])) {
	$upfilename = $_FILES[$uploadtext]['name'];
	$upfile = $_FILES[$uploadtext];
	$upfile_extend_name=extend_2($upfilename);
    if(in_array($upfile_extend_name,$picname)){
		$prefix='pic_'.time().mt_rand(1,99999);
	    $f_upload = new upload_file($prefix,"php,exe,rar,txt",'../upload/',512,$_FILES[$uploadtext]['type']);         
		$f_upload->set_file_name_size($_FILES[$uploadtext]['name'],$_FILES[$uploadtext]['size']);
		$f_upload->set_upfile($_FILES[$uploadtext]['tmp_name']); 
		$file_name = $f_upload->do_save();
	}
	
	if ($file_name) {
		?>
		<script language="javascript" type="text/javascript">
		$(window.opener.document).find("#<?=$uploadtext?>").val('http://<?=URL?>/upload/<?=$file_name?>');
		window.close();
        </script>
		<?
	}
}
?>
<script type="text/javascript">
<!--
function doCheck() 
{
	if(upload.<?=$uploadtext?>.value == '') {
		alert('请选择文件!');
		return false;
	}
	return true;
}
function previewimage()
{
	if(upload.<?=$uploadtext?>.value) $("#previewpic").attr("src", upload.<?=$uploadtext?>.value);
}

function setpicWH(ImgD,w,h)
{
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0)
	{
		flag=true;
		if(image.width/image.height>= w/h)
		{
			if(image.width>w)
			{
				ImgD.width=w;
				ImgD.height=(image.height*w)/image.width;
				ImgD.style.display="block";
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
				ImgD.style.display="block";
			}
		}else{
			if(image.height>h)
			{
				ImgD.height=h;
				ImgD.width=(image.width*h)/image.height;
				ImgD.style.display="block";
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
				ImgD.style.display="block";
			}
		}
	}
}
//-->
</script>
<style type="text/css">
<!--
body { margin:0px; padding:0px; text-align:center}
img { border:#FF9900 1px solid}
-->
</style>
</head>
<body>
<div style=" width:430px; height:auto; background:#CCCCCC; border:#999999 4px solid; margin:auto; margin-top:30px;">

<form name="upload" method="post" action="" enctype="multipart/form-data" onSubmit="return doCheck();">
<table cellpadding="2" cellspacing="1" class="table_form">
    <caption>图片上传</caption>
  <tr>
     <td>
             <input name="<?=$uploadtext?>" type="file" size="15" onChange="previewimage()">
             <input type="submit" name="dosubmit" value=" 上传 ">
			 </td>
   </tr>
  <tr>
     <td>
	 </td>
   </tr>
  <tr>
     <td align="center" style=" padding-top:20px;">
<img id="previewpic" onload="setpicWH(this,300,300)">
<script type="text/javascript">
<!--
if($("#<?=$uploadtext?>",window.opener.document).val())
{
    $("#previewpic").attr("src", $(window.opener.document).find("#<?=$uploadtext?>").val()); 
}
else
{
	$("#previewpic").attr("src","../images/nopic.gif"); 
}
//-->
</script>
			 </td>
   </tr>
</table>
</form>
</div>
</body>
</html>